package net.sureon.common.mail;

import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;

import net.sureon.common.config.SureonConfig;

/**
 * A VO class tha has all the data needed to create an email.
 */
public class MailData {
    /**
     * Constant for mail importance
     */
    public static final int IMPORTANCE_LOW = 5;
    public static final int IMPORTANCE_NORMAL = 3;
    public static final int IMPORTANCE_HIGH = 1;
    /**
     * Constant for mail formats
     */
    public static final String FORMAT_TEXT = "text/plain";
    public static final String FORMAT_HTML = "text/html";

    private String[] recipients;
    private String fromName;
    private String from;
    private String[] replyTo;
    private String[] cc;
    private String[] bcc;
    private String subject;
    private Map replacementMap;
    private List attachments;
    private int importance;
    private String mailFormat;

    /**
     * Default constructor
     */
    public static MailData defaulMailData(){
        MailData data = new MailData();
        data.setFromName(SureonConfig.getInstance().getMailConfig()
            .getFromName());
        data.setReplyTo(new String[] { SureonConfig.getInstance()
            .getMailConfig().getFrom() });
        data.setFrom(SureonConfig.getInstance().getMailConfig().getFrom()); 
        return data;
    }
    public MailData() {
        attachments = new ArrayList();
        importance = IMPORTANCE_NORMAL;
        mailFormat = FORMAT_TEXT;
    }

    /**
     * Returns the list of recipients
     * @return
     */
    public String[] getRecipients() {
        return recipients;
    }

    /**
     * Sets the list of recipients
     * @param recipients
     */
    public void setRecipients(String[] recipients) {
        this.recipients = recipients;
    }

    /**
     * Returns the from
     * @return
     */
    public String getFrom() {
        return from;
    }

    /**
     * Sets the from
     * @param from
     */
    public void setFrom(String from) {
        this.from = from;
    }

    /**
     * Returns the fromName
     * @return
     */
    public String getFromName() {
        return fromName;
    }

    /**
     * Sets the from
     * @param fromName
     */
    public void setFromName(String fromName) {
        this.fromName = fromName;
    }

    /**
     * Returns the reply to field
     * @return
     */
    public String[] getReplyTo() {
        return replyTo;
    }

    /**
     * Sets the reply to
     * @param replyTo
     */
    public void setReplyTo(String[] replyTo) {
        this.replyTo = replyTo;
    }

    /**
     * Returns the map that has values to replace in the template
     * @return
     */
    public Map getReplacementMap() {
        return replacementMap;
    }

    /**
     * Sets the map that has values to replace in the template
     * @param replacementMap
     */
    public void setReplacementMap(Map replacementMap) {
        this.replacementMap = replacementMap;
    }

    /**
     * Returns the filenames of the attachements
     * @return
     */
    public List getAttachments() {
        return attachments;
    }

    /**
     * Adds a filename as a attachement
     * @param attachment
     */
    public void addAttachments(Object attachment) {
        attachments.add(attachment);
    }

    /**
     * Removes the attachements
     * @param attachment
     */
    public void removeAttachments(Object attachment) {
        attachments.remove(attachment);
    }

    /**
     * Returns the importance of the mail
     * @return
     */
    public int getImportance() {
        return importance;
    }

    /**
     * Sets the importance of the mail
     * @param importance
     */
    public void setImportance(int importance) {
        this.importance = importance;
    }

    /**
     * Returns the mail mime's format
     * @return
     */
    public String getMailFormat() {
        return mailFormat;
    }

    /**
     * Sets the mail's mime format
     * @param mailFormat
     */
    public void setMailFormat(String mailFormat) {
        if(mailFormat.equalsIgnoreCase("text")){
            this.mailFormat = FORMAT_TEXT;
        }else if(mailFormat.equalsIgnoreCase("html")){
            this.mailFormat = FORMAT_HTML;
        } else {
            this.mailFormat = mailFormat;
        }
    }

    /**
     * Returns the CC list
     * @return
     */
    public String[] getCc() {
        return cc;
    }

    /**
     * Sets the CC list
     * @param cc
     */
    public void setCc(String[] cc) {
        this.cc = cc;
    }

    /**
     * Gets the BCC list
     * @return
     */
    public String[] getBcc() {
        return bcc;
    }

    /**
     * Sets the BCC Lists
     * @param bcc
     */
    public void setBcc(String[] bcc) {
        this.bcc = bcc;
    }

    /**
     * Gets the subject of the mail
     * @return
     */
    public String getSubject() {
        return subject;
    }

    /**
     * Sets the subject
     * @param subject
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }
}
